package com.ruoyi.web.controller.mes;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.kt.mes.domain.ProductStoreList;
import com.kt.mes.service.IProductStoreListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 成品库存储Controller
 *
 * @author lzc
 * @date 2021-01-23
 */
@RestController
@RequestMapping("/mes/productStorelist")
public class ProductStoreListController extends BaseController
{
    @Autowired
    private IProductStoreListService productStoreListService;

    /**
     * 查询成品库存储列表
     */
    @PreAuthorize("@ss.hasPermi('mes:productStorelist:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductStoreList productStoreList)
    {
        startPage();
        List<ProductStoreList> list = productStoreListService.selectProductStoreListList(productStoreList);
        return getDataTable(list);
    }

    /**
     * 导出成品库存储列表
     */
    @PreAuthorize("@ss.hasPermi('mes:productStorelist:export')")
    @Log(title = "成品库存储", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProductStoreList productStoreList)
    {
        List<ProductStoreList> list = productStoreListService.selectProductStoreListList(productStoreList);
        ExcelUtil<ProductStoreList> util = new ExcelUtil<ProductStoreList>(ProductStoreList.class);
        return util.exportExcel(list, "productStorelist");
    }

    /**
     * 获取成品库存储详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:productStorelist:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(productStoreListService.selectProductStoreListById(id));
    }

    /**
     * 新增成品库存储
     */
    @PreAuthorize("@ss.hasPermi('mes:productStorelist:add')")
    @Log(title = "成品库存储", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductStoreList productStoreList)
    {
        return toAjax(productStoreListService.insertProductStoreList(productStoreList));
    }

    /**
     * 修改成品库存储
     */
    @PreAuthorize("@ss.hasPermi('mes:productStorelist:edit')")
    @Log(title = "成品库存储", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductStoreList productStoreList)
    {
        return toAjax(productStoreListService.updateProductStoreList(productStoreList));
    }

    /**
     * 删除成品库存储
     */
    @PreAuthorize("@ss.hasPermi('mes:productStorelist:remove')")
    @Log(title = "成品库存储", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productStoreListService.deleteProductStoreListByIds(ids));
    }

    @DeleteMapping("/takeOut/{id}")
    public AjaxResult takeOut(@PathVariable Long id){

        productStoreListService.takeOutPS(id);
        return AjaxResult.success();
    }


}
